<!-- 页面外套 -->
<div class="page-wrapper" id="business_customer_failure">

    <!-- 数据网格 -->
    <div class="datagrid datagrid-striped">
        <!-- 工具条组 -->
        <div class="tool-group">
            <form class="tool-search">
                <input type="hidden" name='page'>
                <input type="hidden" name='recPerPage'>
                <div class="im-label">
                    <div class="input-group">
                        <select class="form-control" name="sid">
                            <option value="1">项目编号</option>
                            <option value="2">项目名称</option>
                            <option value="3">工号</option>
                            <option value="4">业务员</option>
                        </select>
                        <span class="input-group-addon fix-border fix-padding"></span>
                        <input type="text" class="form-control" name="search">
                    </div>
                </div>
                <label>
                    <span>项目状态：</span>
                    <select class="form-control" name="state">
                        <option value="0">全部</option>
                        <option value="1">不准申请中</option>
                        <option value="2">未签申请中</option>
                        <option value="3">不准已归库</option>
                        <option value="4">未签已归库</option>
                    </select>
                </label>
                <label><button type="button" class="btn btn-primary tool_search_btn"><i class="icon icon-search"></i> 搜索</button></label>
                <div class="clearfix"></div>
            </form>
        </div>

        <div class="datagrid-container"></div>
        <ul class="pager btn-mini" data-elements="prev,pages,next"></ul>
    </div>

</div>


<!-- 详情外套 -->
<div class="detail-wrapper mode-show" id="business_customer_failure_detail">
    
    <!-- 详情弹框 -->
    <div class="modal modal-for-page fade detail_box" aria-hidden="false">
        <div class="modal-dialog modal-fullscreen">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">失败审批详情</h4>
                </div>
                <div class="modal-body modal-scroll">

                    <!-- 操作按钮 -->
                    <button class="btn" data-dismiss="modal"><i class="icon icon-arrow-left"></i>  返回</button>
                    <button class="btn btn-primary" data-toggle="modal" data-target=".detail_backToSalesman_box">打回商务继续跟踪</button>
                    <button class="btn btn-primary" data-toggle="modal" data-target=".detail_backToDesign_box">打回主案经理</button>
                    <button class="btn btn-primary" data-toggle="modal" data-target=".detail_sink_box">同意归库</button>

                    <!-- 数据表单 -->
                    <form class="detail_box_form">
                        <input type="hidden" name="cid">
                        <table class="table"><!--JS推进--></table>
                    </form>

                   <!-- 切换表格 -->
                    <ul class="nav nav-tabs">
                        <li class="active"><a data-tab="" href=".detail_tab1">业务回访</a></li>
                        <li><a data-tab="" href=".detail_tab2">设计回访</a></li>
                        <li><a data-tab="" href=".detail_tab3">过程记录</a></li>
                    </ul>

                    <div class="tab-content">
                        <div class="tab-pane active detail_tab1">
                            <form class="tool-search">
                                <input type="hidden" name='page'>
                                <input type="hidden" name='recPerPage'>
                                <input type="hidden" name="cid" value="null">
                            </form>
                            <div class="datagrid datagrid-striped">
                                <div class="datagrid-container"></div>
                                <ul class="pager btn-mini" data-elements="first_icon,prev_icon,next_icon,last_icon,size_menu,goto,page_of_total_text" data-menu-direction="dropup"></ul>
                            </div>
                        </div>
                        <div class="tab-pane detail_tab2">
                            <form class="tool-search">
                                <input type="hidden" name='page'>
                                <input type="hidden" name='recPerPage'>
                                <input type="hidden" name="cid" value="null">
                            </form>
                            <div class="datagrid datagrid-striped">
                                <div class="datagrid-container"></div>
                                <ul class="pager btn-mini" data-elements="first_icon,prev_icon,next_icon,last_icon,size_menu,goto,page_of_total_text" data-menu-direction="dropup"></ul>
                            </div>
                        </div>
                        <div class="tab-pane detail_tab3">
                            <form class="tool-search">
                                <input type="hidden" name='page'>
                                <input type="hidden" name='recPerPage'>
                                <input type="hidden" name="cid" value="null">
                            </form>
                            <div class="datagrid datagrid-striped">
                                <div class="datagrid-container"></div>
                                <ul class="pager btn-mini" data-elements="first_icon,prev_icon,next_icon,last_icon,size_menu,goto,page_of_total_text" data-menu-direction="dropup"></ul>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>

    <!-- 打回商务继续跟踪 -->
    <div class="modal modal-for-page fade detail_backToSalesman_box" aria-hidden="false">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">打回商务继续跟踪</h4>
                </div>
                <div class="modal-body"><div class="container">确定打回商务继续跟踪吗？</div><form><input type="hidden" name="cid"></form></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary detail_backToSalesman_submit">提交</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 打回主案经理 -->
    <div class="modal modal-for-page fade detail_backToDesign_box" aria-hidden="false">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">打回主案经理</h4>
                </div>
                <div class="modal-body"><div class="container">确定打回主案经理吗？</div><form><input type="hidden" name="cid"></form></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary detail_backToDesign_submit">提交</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 同意归库 -->
    <div class="modal modal-for-page fade detail_sink_box" aria-hidden="false">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">同意归库</h4>
                </div>
                <div class="modal-body"><div class="container">确定同意归库吗？</div><form><input type="hidden" name="cid"></form></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary detail_sink_submit">提交</button>
                </div>
            </div>
        </div>
    </div>

</div>

<script>
$(function() {
    //变量声明-----------------------------------------------------------------------------------------------
    var business_customer_failure = $("#business_customer_failure"); //页面ID
    var business_customer_failure_api = {
        datagrid : API.test_datagrid, // 数据表格
        show : LOCAL + "Test/Template/customer.json", // 详情查看
        backToSalesman : API.test_response, // 打回商务继续跟踪
        backToDesign : API.test_response, // 打回主案经理
        sink : API.test_response, // 同意归库
        tab1 : API.test_datagrid, // 切换表格1
        tab2 : API.test_datagrid, // 切换表格2
        tab3 : API.test_datagrid, // 切换表格3
    }

    //数据表格-----------------------------------------------------------------------------------------------
    //数据源
    var business_customer_failure_dataSource = {
        cols   : [
            {name:"username",label:"项目编号",width:100,html:true,
                valueOperator : {
                    getter : function(dataValue,cell){
                        return `<a class="line_show_btn" dataId="${cell.config.data.id}">${dataValue}</a>`;
                    }
                }
            },
            {name:"text8",   label:"项目名称",    width:150},
            {name:"name",    label:"联系人",      width:80 },
            {name:"name",    label:"信息员",      width:80 },
            {name:"name",    label:"业务员",      width:80 },
            {name:"name",    label:"设计师",      width:80 },
            {name:"tex10",   label:"项目状态",    width:150},
            {name:"text2",   label:"房源状态",    width:80 },
            {name:"tex10",   label:"装修地址",    width:150},
        ],
        remote : function(){
            return zui_datagrid_remote({
                page_dom : business_customer_failure, 
                url      : business_customer_failure_api.datagrid
            });
        },
        remoteConverter : function(data){ 
            return zui_datagrid_filter({
                page_dom : business_customer_failure,
                data     : data
            });
        }
    };
    //实例化
    business_customer_failure.find('.datagrid').datagrid(
        zui_datagrid_option({
            datagrid   : business_customer_failure.find('.datagrid'),
            dataSource : business_customer_failure_dataSource,
        })
    );
    var business_customer_failure_datagrid_obj =  business_customer_failure.find('.datagrid').data("zui.datagrid");
    //搜索
    business_customer_failure.find('.tool_search_btn').click(function(){ 
        zui_datagrid_render({
            datagrid_obj : business_customer_failure_datagrid_obj,
            dataSource   : business_customer_failure_dataSource
        }); 
    });


    //详情部分---------------------------------------------------------------------------
    //变量声明
    var business_customer_failure_detail = $("#business_customer_failure_detail");
    var business_customer_failure_detail_dataSource_tab1 = {
        cols   : [
            {name:"name",    label:"回访人",      width:80 },
            {name:"tex10",   label:"回访内容",    width:200},
            {name:"datetime",label:"回访时间",    width:140},
            {name:"datetime",label:"下次回访时间",width:140},
        ],
        remote : function(){
            return zui_datagrid_remote({
                page_dom : business_customer_failure_detail.find('.detail_tab1'), 
                url      : business_customer_failure_api.tab1
            });
        },
        remoteConverter : function(data){ 
            return zui_datagrid_filter({
                page_dom : business_customer_failure_detail.find('.detail_tab1'),
                data     : data
            });
        }
    }
    var business_customer_failure_detail_dataSource_tab2 = {
        cols   : [
            {name:"username",label:"回访人",      width:80 },
            {name:"datetime",label:"回访时间",    width:140},
            {name:"datetime",label:"下次回访时间",width:140},
            {name:"text5",   label:"负责人情况",  width:200},
            {name:"text2",   label:"对手进展",    width:80 },
            {name:"text2",   label:"跟进情况",    width:80 },
            {name:"state",   label:"现阶段困难",  width:180},
            {name:"text2",   label:"外协情况",    width:80 },
            {name:"state",   label:"经理批复",    width:180}
        ],
        remote : function(){
            return zui_datagrid_remote({
                page_dom : business_customer_failure_detail.find('.detail_tab2'), 
                url      : business_customer_failure_api.tab2
            });
        },
        remoteConverter : function(data){ 
            return zui_datagrid_filter({
                page_dom : business_customer_failure_detail.find('.detail_tab2'),
                data     : data
            });
        }
    }
    var business_customer_failure_detail_dataSource_tab3 = {
        cols   : [
            {name:"name",    label:"操作人",  width:80 },
            {name:"datetime",label:"操作时间",width:140},
            {name:"tex10",   label:"过程说明",width:200}
        ],
        remote : function(){
            return zui_datagrid_remote({
                page_dom : business_customer_failure_detail.find('.detail_tab3'), 
                url      : business_customer_failure_api.tab3
            });
        },
        remoteConverter : function(data){ 
            return zui_datagrid_filter({
                page_dom : business_customer_failure_detail.find('.detail_tab3'),
                data     : data
            });
        }
    }

    //详情弹框
    business_customer_failure.on("click", '.line_show_btn', function() {
        common_form_reset();
        var dataId = $(this).attr('dataId');
        business_customer_failure_detail.find('[name="cid"]').val(dataId); // 详情ID赋值(多个)
        //远程请求
        $.ajax({
            url     : business_customer_failure_api.show,
            type    : "post",
            dataType: "json",
            data    : { id: dataId },
            success : function(data){
                if( data.status>0 ){
                    var data = data.data;
                    //基础表格
                    var temp = `
                    <thead><tr><td colspan="3"><div class="flex-box"><b>项目状态</b>${data.itemstatename}</div></td></tr></thead>
                    <tbody>
                        <tr>
                            <td><div class="flex-box"><b>项目编号</b>${data.number}</span></div></td>
                            <td><div class="flex-box"><b>项目名称</b>${data.case}</span></div></td>
                            <td><div class="flex-box"><b>项目类型</b>${data.typename}   </div></td>
                        </tr>
                        <tr>
                            <td><div class="flex-box"><b>业务员</b>${data.salesman}    </div></td>
                            <td><div class="flex-box"><b>信息员</b>${data.providername}</div></td>
                            <td><div class="flex-box"><b>设计师</b>${data.designer}    </div></td>
                        </tr>
                        <tr>
                            <td><div class="flex-box"><b>联系人1 </b>${data.user1}</div></td>
                            <td><div class="flex-box"><b>手机1   </b>${data.tel1} </div></td>
                            <td><div class="flex-box"><b>办公电话</b>${data.tel0} </div></td>
                        </tr>
                        <tr>
                            <td><div class="flex-box"><b>房源状态</b>${data.sourcestatename}</div></td>
                            <td><div class="flex-box"><b>房屋状态</b>${data.housestatename} </div></td>
                            <td><div class="flex-box"><b>房屋类型</b>${data.housetypename}  </div></td>
                        </tr>
                        <tr>
                            <td><div class="flex-box"><b>装修面积</b>${data.decoarea}    </div></td>
                            <td><div class="flex-box"><b>装修意向</b>${data.decotodoname}</div></td>
                            <td><div class="flex-box"><b>装修服务</b>${data.decoservname}</div></td>
                        </tr>
                        <tr>
                            <td><div class="flex-box"><b>交房日期</b>${data.housedate1}</div></td>
                            <td><div class="flex-box"><b>期望工期</b>${data.housedate2}</div></td>
                            <td><div class="flex-box"><b>装修地址</b>${data.decoaddr}  </div></td>
                        </tr>
                        <tr>
                            <td><div class="flex-box"><b>联系人2</b>${data.user2}</div></td>
                            <td><div class="flex-box"><b>手机2  </b>${data.tel2} </div></td>
                            <td><div class="flex-box"><b>手机3  </b>${data.tel3} </div></td>
                        </tr>
                        <tr>
                            <td><div class="flex-box"><b>对手数量</b>${data.rivalnumb}</div></td>
                            <td><div class="flex-box"><b>对手进展</b>${data.rivalstepname}</div></td>                        
                            <td></td>
                        </tr>
                        <tr>
                            <td><div class="flex-box"><b>乘车路线</b>${data.busline}</div></td>
                            <td colspan="2"><div class="flex-box"><b>办公地址</b>${data.addr}</div></td>
                        </tr>
                        <tr><td colspan="3"><div class="flex-box" style="height:35px;"><b>备注信息</b>${data.text}</div></td></tr>
                    </tbody>
                    `;
                    business_customer_failure_detail.find('.detail_box .detail_box_form table').html(temp); // DOM填充
                    // um_data_set( business_customer_failure_detail.find('.detail_box .detail_box_form'), data ); //修改赋值
                    // business_customer_failure_detail.addClass("mode-show").removeClass("mode-edit"); // 样式初始化
                    //切换表格刷新
                    zui_datagrid_render({
                        datagrid_obj : business_customer_failure_detail.find('.detail_tab1 .datagrid').data("zui.datagrid"),
                        dataSource   : business_customer_failure_detail_dataSource_tab1
                    });
                    zui_datagrid_render({
                        datagrid_obj : business_customer_failure_detail.find('.detail_tab2 .datagrid').data("zui.datagrid"),
                        dataSource   : business_customer_failure_detail_dataSource_tab2
                    });
                    zui_datagrid_render({
                        datagrid_obj : business_customer_failure_detail.find('.detail_tab3 .datagrid').data("zui.datagrid"),
                        dataSource   : business_customer_failure_detail_dataSource_tab3
                    });
                    business_customer_failure_detail.find('.detail_box').modal('show'); // 弹框显示
                } else {
                    um_tip(data.message,"1500","text-danger");
                }
            }
        });
 
    });

    //操作按钮-打回商务继续跟踪
    business_customer_failure_detail.on("click", '.detail_backToSalesman_submit', function() {
        um_data_submit({
            url         : business_customer_failure_api.backToSalesman,
            form        : business_customer_failure_detail.find('.detail_backToSalesman_box form'),
            datagridDom : business_customer_failure.find('.datagrid'),
            dataSource  : business_customer_failure_dataSource,
        });
    });

    //操作按钮-打回主案经理
    business_customer_failure_detail.on("click", '.detail_backToDesign_submit', function() {
        um_data_submit({
            url         : business_customer_failure_api.backToDesign,
            form        : business_customer_failure_detail.find('.detail_backToDesign_box form'),
            datagridDom : business_customer_failure.find('.datagrid'),
            dataSource  : business_customer_failure_dataSource,
        });
    });

    //操作按钮-同意归库
    business_customer_failure_detail.on("click", '.detail_sink_submit', function() {
        um_data_submit({
            url         : business_customer_failure_api.sink,
            form        : business_customer_failure_detail.find('.detail_sink_box form'),
            datagridDom : business_customer_failure.find('.datagrid'),
            dataSource  : business_customer_failure_dataSource,
        });
    });

    //切换表格-业务回访------------------------------------------------------------------------
    business_customer_failure_detail.find('.detail_tab1 .datagrid').datagrid(
        zui_datagrid_option({
            height     : 400,
            datagrid   : business_customer_failure_detail.find('.detail_tab1 .datagrid'),
            dataSource : business_customer_failure_detail_dataSource_tab1
        })
    );
    //切换表格-设计回访
    business_customer_failure_detail.find('.detail_tab2 .datagrid').datagrid(
        zui_datagrid_option({
            height     : 400,
            datagrid   : business_customer_failure_detail.find('.detail_tab2 .datagrid'),
            dataSource : business_customer_failure_detail_dataSource_tab2
        })
    );
    //切换表格-过程记录
    business_customer_failure_detail.find('.detail_tab3 .datagrid').datagrid(
        zui_datagrid_option({
            height     : 400,
            datagrid   : business_customer_failure_detail.find('.detail_tab3 .datagrid'),
            dataSource : business_customer_failure_detail_dataSource_tab3
        })
    );

}); //预加载结尾
</script>
